﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>大棚气象信息采集与控制系统服务端与客户端通信协议</title>
</head>
<body>
<div id="wmd-preview" class="wmd-preview"><div class="md-section-divider"></div><div class="md-section-divider"></div><h1 data-anchor-id="b1u9" id="大棚气象信息采集与控制系统服务端与客户端通信协议">大棚气象信息采集与控制系统服务端与客户端通信协议</h1><hr><p data-anchor-id="u0qx"><code>注意事项</code></p><blockquote data-anchor-id="f20w" class="white-blockquote">
  <ul>
  <li>发送的字符串命令必须压缩为一行，服务端将根据每一行执行一次业务逻辑</li>
  <li>发送字符串的结尾必须以<code>"\r\n"</code>结尾，16进制数为<code>0D 0A</code></li>
  <li>发送的内容中不能有中文</li>
  <li>使用<code>TCP</code>协议，端口暂定<code>8081</code></li>
  </ul>
</blockquote><hr><blockquote data-anchor-id="coxw" class="white-blockquote">
  <h4 id="命令目录">命令目录</h4>
  
  <ol>
  <li>客户端基本数据提交</li>
  <li>客户端心跳包</li>
  <li>服务端命令下达</li>
  </ol>
</blockquote><hr><div class="md-section-divider"></div><h3 data-anchor-id="bnkl" id="1客户端基本数据提交">1.客户端基本数据提交</h3><blockquote data-anchor-id="1fb8" class="white-blockquote">
  <p>数据传输方向：客户端-&gt;服务端</p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="8ebu"><ol class="linenums"><li class="L0"><code><span class="com">//可视化字符串：</span></code></li><li class="L1"><code><span class="pun">{</span></code></li><li class="L2"><code><span class="pln">    </span><span class="str">"DeviceID"</span><span class="pun">:</span><span class="str">"1001"</span><span class="pun">,</span></code></li><li class="L3"><code><span class="pln">    </span><span class="str">"Command"</span><span class="pun">:</span><span class="str">"Environment"</span><span class="pun">,</span></code></li><li class="L4"><code><span class="pln">    </span><span class="str">"AirTemperature"</span><span class="pun">:</span><span class="str">"20"</span><span class="pun">,</span></code></li><li class="L5"><code><span class="pln">    </span><span class="str">"AirHumidity"</span><span class="pun">:</span><span class="str">"20"</span><span class="pun">,</span></code></li><li class="L6"><code><span class="pln">    </span><span class="str">"SoilHumidity"</span><span class="pun">:</span><span class="str">"20"</span><span class="pun">,</span></code></li><li class="L7"><code><span class="pln">    </span><span class="str">"Longitude"</span><span class="pun">:</span><span class="str">"118.729569"</span><span class="pun">,</span></code></li><li class="L8"><code><span class="pln">    </span><span class="str">"Latitude"</span><span class="pun">:</span><span class="str">"32.210515"</span><span class="pun">,</span></code></li><li class="L9"><code><span class="pln">    </span><span class="str">"ReceivedTime"</span><span class="pun">:</span><span class="str">"2015-11-11 11:11:11"</span></code></li><li class="L0"><code><span class="pun">}</span></code></li><li class="L1"><code><span class="com">//实际发送示例（C语言）：</span></code></li><li class="L2"><code><span class="typ">String</span><span class="pln"> preparedStr </span><span class="pun">=</span><span class="pln"> </span><span class="str">"{\"DeviceID\":\"1001\",\"Command\":\"Environment\",\"AirTemperature\":\"20\",\"AirHumidity\":\"20\",\"SoilHumidity\":\"20\",\"Longitude\":\"118.729569\",\"Latitude\":\"32.210515\",\"ReceivedTime\":\"2015-11-11 11:11:11\"}"</span><span class="pun">+</span><span class="str">"\r\n"</span><span class="pun">;</span></code></li></ol></pre><hr><div class="md-section-divider"></div><h3 data-anchor-id="6ww5" id="2客户端心跳包">2.客户端心跳包</h3><blockquote data-anchor-id="e5oe" class="white-blockquote">
  <p>数据传输方向：客户端-&gt;服务端</p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="bdkr"><ol class="linenums"><li class="L0"><code><span class="com">//可视化字符串：</span></code></li><li class="L1"><code><span class="pun">{</span></code></li><li class="L2"><code><span class="pln">    </span><span class="str">"DeviceID"</span><span class="pun">:</span><span class="str">"1001"</span><span class="pun">,</span></code></li><li class="L3"><code><span class="pln">    </span><span class="str">"Command"</span><span class="pun">:</span><span class="str">"Heart"</span><span class="pun">,</span></code></li><li class="L4"><code><span class="pln">    </span><span class="str">"ReceivedTime"</span><span class="pun">:</span><span class="str">"2015-11-11 11:11:11"</span></code></li><li class="L5"><code><span class="pun">}</span></code></li><li class="L6"><code><span class="com">//实际发送示例（C语言）：</span></code></li><li class="L7"><code><span class="typ">String</span><span class="pln"> preparedStr </span><span class="pun">=</span><span class="pln"> </span><span class="str">"{\"DeviceID\":\"1001\",\"Command\":\"Heart\",\"ReceivedTime\":\"2015-11-11 11:11:11\"}"</span><span class="pun">+</span><span class="str">"\r\n"</span><span class="pun">;</span></code></li></ol></pre><hr><div class="md-section-divider"></div><h3 data-anchor-id="nt5c" id="3服务端命令下达-1">3.服务端命令下达</h3><blockquote data-anchor-id="0x97" class="white-blockquote">
  <p>数据传输方向：服务端-&gt;客户端</p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="svnm"><ol class="linenums"><li class="L0"><code><span class="com">//可视化字符串：</span></code></li><li class="L1"><code><span class="pun">{</span></code></li><li class="L2"><code><span class="pln">    </span><span class="str">"DeviceID"</span><span class="pun">:</span><span class="str">"1001"</span><span class="pun">,</span></code></li><li class="L3"><code><span class="pln">    </span><span class="str">"Command"</span><span class="pun">:</span><span class="str">"Switch"</span><span class="pun">,</span></code></li><li class="L4"><code><span class="pln">    </span><span class="str">"Sunshade"</span><span class="pun">:</span><span class="str">"On"</span><span class="pun">,</span></code></li><li class="L5"><code><span class="pln">    </span><span class="str">"Spray"</span><span class="pun">:</span><span class="str">"On"</span><span class="pun">,</span></code></li><li class="L6"><code><span class="pln">    </span><span class="str">"Drip"</span><span class="pun">:</span><span class="str">"On"</span><span class="pun">,</span></code></li><li class="L7"><code><span class="pln">    </span><span class="str">"UpdateTime"</span><span class="pun">:</span><span class="str">"2015-11-11 11:11:11"</span></code></li><li class="L8"><code><span class="pun">}</span></code></li><li class="L9"><code><span class="com">//实际发送示例（C语言）：</span></code></li><li class="L0"><code><span class="typ">String</span><span class="pln"> preparedStr </span><span class="pun">=</span><span class="pln"> </span><span class="str">"{\"DeviceID\":\"1001\",\"Command\":\"Switch\",\"Sunshade\":\"On\",\"Spray\":\"On\",\"Drip\":\"On\",\"UpdateTime\":\"2015-11-11 11:11:11\"}"</span><span class="pun">+</span><span class="str">"\r\n"</span><span class="pun">;</span></code></li></ol></pre><hr></div>
</body>
</html>